package cn.bigfire.compiler.dragon.appendixA.handwrite.inter;

import cn.bigfire.compiler.dragon.appendixA.handwrite.lexer.Token;
import cn.bigfire.compiler.dragon.appendixA.handwrite.symbols.Type;

public class Expr extends Node {

    public Token token;
    public Type type;

    public Expr(Token token, Type type) {
        this.token = token;
        this.type = type;
    }

    public Expr gen(){
        return this;
    }

    public Expr reduce(){
        return this;
    }

    public void jumping(int t, int f) {
        emitJumps(toString(), t, f);
    }

    public void emitJumps(String test, int t, int f) {
        if (t != 0 && f != 0) {
            emit("if " + toString() + " goto L" + t);
            emit("goto L" + f);
        } else if (t != 0) {
            emit("if " + test + " goto L" + t);
        } else if (f != 0) {
            emit("iffalse" + test + " goto L" + f);
        }else {

        }
    }


    @Override
    public String toString() {
        return token.toString();
    }



}
